package com.bitin.adorn.modules.system.api;

import com.bitin.adorn.modules.system.domain.Employee;
import com.bitin.adorn.modules.system.service.EmployeeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Mr.Lu
 * @since 2024/5/30 15:48
 */
@Tag(name = "用户")
@RestController
@RequestMapping("/v1/user")
@RequiredArgsConstructor
@Slf4j
public class EmployeeController {

    private final EmployeeService employeeService;

    @Operation(summary = "用户-初始化", description = "新增用户")
    @PostMapping("/init")
    public Employee add() {
        return employeeService.init();
    }

    @Operation(summary = "用户-新增", description = "新增用户")
    @PostMapping("/save")
    public Employee save(@RequestBody Employee user) {
        return employeeService.save(user);
    }

    @Operation(summary = "用户-列表")
    @GetMapping("/list")
    public List<Employee> list() {
        return employeeService.list();
    }

    @Operation(summary = "用户")
    @GetMapping("/{id}")
    public Employee one(@PathVariable("id") Long id) {
        return employeeService.findById(id);
    }

    @Operation(summary = "用户-删除")
    @DeleteMapping("/{id}")
    public void remove(@PathVariable("id") Long id) {
        employeeService.deleteById(id);
    }

    @Operation(summary = "用户-绑定角色")
    @PostMapping("/bind")
    public Employee bind(@RequestParam("id") Long id, @RequestParam("roleId") Long roleId) {
        return employeeService.bind(id, roleId);
    }
}
